<% layout('/layouts/default.html', {title: '生产流程模板管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text(t9mWorkflowMaster.isNewRecord ? '新增生产流程模板' : '编辑生产流程模板')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${t9mWorkflowMaster}" action="${ctx}/t9m/t9mWorkflowMaster/save" method="post" class="form-horizontal"
		onSubmit="return app.beforeSubmit(this)">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="id"/>
				<#form:hidden path="isModified"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('生产流程名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="f9mWorkflow" maxlength="18" class="form-control required"
								/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="f9mRemark" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('流程模板')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="f9mIsTemplate" dictType="YesNo" class="form-control required" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">${text('图片上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadImage" bizKey="${t9mWorkflowMaster.id}" bizType="t9mWorkflowMaster_image"
									uploadType="image" class="" readonly="false"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('t9m_job_group')}</h4>
				<div class="ml10 mr10">
					<table id="t9mJobGroupDataGrid"></table>
					<% if (hasPermi('t9m:t9mWorkflowMaster:edit')){ %>
						<a href="#" id="t9mJobGroupDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('t9m:t9mWorkflowMaster:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
	mFieldsToUpper="f9mWorkflow,f9mGroup,f9mRpdRtnGroup".split(",");
	var lvDetGrid="#t9mJobGroupDataGrid";
//初始化t9m_job_groupDataGrid对象
   $(lvDetGrid).dataGrid({
	data:${toJson(t9mWorkflowMaster.t9mJobGroupList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'id', editable:true, hidden:true},
		{header:'isModified', name:'isModified', editable:true, hidden:true},
		{header:'${text("站位名称")}', name:'f9mGroup', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'10', 'class':'form-control'}},

		{header:'${text("排序")}', name:'f9mSeq', hidden:true, editable:true},
		{header:'${text("维修后返回站位")}', name:'f9mRpdRtnGroup', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control required'}},
		{header:'${text("生产线类型")}', name:'f9mLineType', width:100, 
			editable:true, edittype:'select', editoptions:{'class':'form-control required',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('linetype')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("站位类型")}', name:'f9mOpType', width:100, 
			editable:true, edittype:'select', editoptions:{'class':'form-control required',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('optype')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("停拉控制")}', name:'f9mStoplineControl', width:100, 
			editable:true, edittype:'select', editoptions:{'class':'form-control required',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('YesNo')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("间隔分钟数")}', name:'f9mInterval', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control required digits'}},
		{header:'${text("f9m_workflow_parent_id")}', name:'f9mWorkflowParentId.id', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
				var actions = [];
				if (val == 'new'){
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\''+lvDetGrid+'\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}else{
					//actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要停用这条数据吗？")}\', function(){$(\''+lvDetGrid+'\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DISABLE+'\');});return false;"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
					if (row.status == Global.STATUS_NORMAL){
						var lvScript='<a title="${text("停用这条数据")}" href="#" onclick="return app.gridRowStatusAction(this,\'${text("你确认要停用这条数据吗？")}\',\''+lvDetGrid+'\',\''+obj.rowId+'\');"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;';
						actions.push(lvScript);
					}
					if (row.status == Global.STATUS_DISABLE){
						//actions.push('<a href="${ctx}/tg/tgSeries/enable-child?id='+row.id+'" class="btnList" title="${text("启用产品系列型号")}" data-confirm="${text("确认要启用该产品型号吗？")}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
						var lvScript='<a title="${text("启用这条数据")}"  href="#" onclick="return app.gridRowStatusAction(this,\'${text("你确认要启用这条数据吗？")}\',\''+lvDetGrid+'\',\''+obj.rowId+'\');"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;';
						actions.push(lvScript);
					}
					//actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\''+lvDetGrid+'\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					var lvDelScript='<a title="${text("删除这条数据")}"  href="#" onclick="return app.gridRowStatusAction(this,\'${text("你确认要删除这条数据吗？")}\',\''+lvDetGrid+'\',\''+obj.rowId+'\',\'1\');"><i class="fa fa-trash-o"></i></a>&nbsp;';
					actions.push(lvDelScript);
				}
				return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#t9mJobGroupDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 't9mJobGroupList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,id,isModified,f9mGroup,f9mSeq,f9mRpdRtnGroup,f9mIsTemplate,f9mLineType,f9mOpType,f9mStoplineControl,f9mInterval,createBy,createDate,updateBy,updateDate,f9mWorkflowParentId.id,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	},
	afterInsertRow:function(rowid ,rowdata ,rowelem){
		//console.log('afterInsertRow');
		//console.log(rowid,rowdata,rowelem);
		//关键字转大写
		setTimeout(function(){
			app.setUpperCaseGridRow(rowid);
			app.setHookChangeEvent(rowid,rowdata);
		},500); //必须要延时,因为这个事件发生时还没有input 创建
	},
});
</script>
<link rel="stylesheet" href="${ctxStatic}/jquery-ui/jquery-ui.css?${_version}" />
<script src="${ctxStatic}/jquery-ui/jquery-ui.js?${_version}"tpjob></script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
$( function() {
	$("#t9mJobGroupDataGrid tbody").sortable(
		{
		   update: function( event, ui ) {
		   	  var lvnStart=5;
			   $("#t9mJobGroupDataGrid tbody tr[class!='jqgfirstrow']").children("td").children("input[name='f9mSeq']")
					   .each(function(i,o){
					   	$(o).val(lvnStart);
						   lvnStart+=5;
					   });
			   $("#t9mJobGroupDataGrid tbody tr[class!='jqgfirstrow']").each(function(i,o){
			   	  var lvId=$(o).attr("id");
			   	  if (!lvId)return;
			   	  $("#{0}_isModified".format(lvId)).val("1");
			   });
		   }
	    }
	);
	$( ".sortable" ).disableSelection();
	if ("${t9mWorkflowMaster.id}"==""||"${t9mWorkflowMaster.id}"=="null"){

	}
	else{
		$("#inputForm #f9mWorkflow").attr("readOnly","readOnly");
	}
	$("#f9mIsTemplate").iCheck('disable');

} );
</script>